class Solution
{
public:
    string be_string(const array<int, 26> &count)
    {
        string tmp;
        for (int i = 0; i < 26; ++i)
            if (count[i])
            {
                tmp += 'a' + i;
                tmp += to_string(count[i]);
            }
        return tmp;
    }
    vector<vector<string>> groupAnagrams(vector<string> &strs)
    {
        unordered_map<string, vector<string>> m;
        for (const auto &str : strs)
        {
            array<int, 26> count = {};
            for (auto e : str)
                count[e - 'a']++;
            string tmp = be_string(count);
            m[tmp].push_back(str);
        }
        vector<vector<string>> ans;
        for (const auto &[x, y] : m)
            ans.push_back(y);
        return ans;
    }
};